begintownscript;

variables;
short choice;

body;

beginstate 0; //INIT_STATE

	//groups
	add_range_to_group(6,10,1); //loyalist ambushers


	if(get_flag(12,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"After following the tunnel for a while, you emerge into a jungle clearing. It's not a comfortable path, but it works. Now you just have to make sure that the Loyalists don't find it.",0);
		add_dialog_str(1,"You take a look around the clearing.",0);
		run_dialog(1);
		
		force_instant_terrain_redraw();
		pause(15);
		
		reset_dialog();
		add_dialog_str(0,"And then you notice the group of Loyalists staring at you as you dust yourselves off. One of them laughs.",0);
		add_dialog_str(1,"Then they raise their weapons and advance.",0);
		run_dialog(1);
		
		set_attitude(1001,10); //make the loyalists hostile
		
		//if Carli's in the party, she notices Matthew
		if(character_in_party(622) > 0) {
			pause(3);
			play_sound(-48); //going berzerk
			reset_dialog();
			add_dialog_str(0,"You're surprised to hear Carli let loose a bellow of rage. She points at one of the archers in the back of the group.",0);
			add_dialog_str(1,"_Matthew! You bastard, I'm going to cut you to pieces!_",15);
			//if you know about Matthew
			if(get_flag(6,12) == 1)
				add_dialog_str(2,"Having heard her story, you can't help but glare coldly at Matthew as well. He looks rather terrified.",0);
			//otherwise...
				add_dialog_str(2,"You have no idea what she's going on about, but the Loyalist looks terrified.",0);
			run_dialog(1);
			set_flag(12,1,1);
			set_name(6,"Matthew");
			}
		
		set_flag(12,0,1);
		}

break;

beginstate 1; //EXIT_STATE
break;

beginstate 2; //START_STATE
	//Checking for the lead pc each turn... not necessary here
	//pc_counter = 0;
	//while(char_ok(pc_counter) == 0) {
	//	pc_counter = pc_counter + 1;
	//	}
	//lead_char = pc_counter;
	
	//check to see if the Loyalists are all dead
	if((num_chars_in_group(1) == 0) && (get_flag(12,3) == 0)) {
		reset_dialog();
		//if Carli's there
		if(character_in_party(622) > 0) {
			add_dialog_str(0,"Breathing heavily, you make sure the Loyalists are dead by kicking them several times. Particularly Matthew.",0);
			add_dialog_str(1,"After a few spirited kicks, Carli waves you away so she can have a turn. She looks a little relieved, but still wears an understandably grim face.",0);
			}
		else
			add_dialog_str(0,"Breathing heavily, you make sure the last of the Loyalists is truly dead by kicking him several times. You survey your surroundings.",0);
		add_dialog_str(2,"Right now, you're somewhere in the jungle. You don't think the Loyalists know where you are, but it's hard to say. Somehow, you need to make it to their flagship, wherever that is.",0);
		add_dialog_str(3,"Then you hear a horn sound out across the trees, and a sinking feeling grips you.",0);
		run_dialog(1);
		
		set_flag(12,3,1);
		}
break;

beginstate 10; //don't go back
	block_entry(1);
	message_dialog("There's nothing to be gained by going back into the tunnel, particularly now that the Loyalists have spotted you.","");
break;

beginstate 15; //leaving the clearing
	block_entry(1);
	reset_dialog();
	if(num_chars_in_group(1) == 0) {
		//if the Loyalists are dead
		add_dialog_str(0,"You flee the clearing, only pausing briefly to kick one of the fallen Loyalists.",0);
		if(character_in_party(622) > 0)
			//if Carli is with you
			add_dialog_str(1,"Carli follows reluctantly, looking back one more time to Matthew's corpse. She mutters something under her breath.",0);
		set_flag(12,3,1);
		}
	else {
		//if the Loyalists aren't all dead
		add_dialog_str(0,"You flee the clearing, easily outdistancing the remaining Loyalists.",0);
		if((character_in_party(622) > 0) && (char_ok(6) == 1))
			//if Carli is with you and Matthew survived
			add_dialog_str(1,"Carli follows reluctantly, looking back one more time to glare at Matthew. She mutters something under her breath.",0);
		else if((character_in_party(622) > 0) && (char_ok(6) != 1))
			//if Carli is with you and Matthew died
			add_dialog_str(1,"Carli follows reluctantly, looking back one more time to Matthew's corpse. She mutters something under her breath.",0);
		}
	add_dialog_str(2,"Hopefully, you can evade the other Loyalists on the island...",0);
	run_dialog(1);

	pause(3);
	
	reset_dialog();
	add_dialog_str(0,"Of course, it's not that easy. As you try to navigate the dense and dark jungle, you find it difficult to make any meaningful progress. At least once you go in a full circle.",0);
	add_dialog_str(1,"Thus, it is no surprise when you are eventually captured by a patrol of Loyalists. They knock you unconscious and drag you away...",0);
	run_dialog(1);

	//move the action to the ship
	move_to_new_town(7,15,16);

break;